package com.ytjj.qmyx.admin.controller.imController;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.ImConfigInfo;
import com.ytjj.qmyx.admin.model.vo.ImConfigInfoVO;

import com.ytjj.qmyx.admin.service.imService.ImConfigInfoService;
import com.ytjj.qmyx.admin.service.imService.ImServiceUserService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 客服设置管理controller
 */
@RestController
@RequestMapping("/imConfig")
@Slf4j
public class ImConfigInfoController {

    @Autowired
    private ImConfigInfoService imConfigInfoService;


    /**
     *  修改设置开关
     * 参数:"id","offFlag"
     * @return
     */
    @PostMapping("/updateConfig")
    public CommonResult updateConfig(@RequestBody ImConfigInfoVO imConfigInfo){
        Integer adminId = UserUtil.getAdminId();
        imConfigInfo.setUpdateUser(adminId);
        Integer count = imConfigInfoService.updateConfig(imConfigInfo);
        if (count > 0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     *  查询全部设置
     * @return
     */
    @PostMapping("/selectConfig")
    public CommonResult selectConfig(){
        List<ImConfigInfo> list = imConfigInfoService.selectAll();
        if (CollectionUtils.isEmpty(list)){
            return CommonResult.failed();
        }
        return CommonResult.success(list);
    }
}
